package com.leyou.item.service;

import com.leyou.item.mapper.SpecGroupMapper;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecService {

    @Autowired
    private SpecGroupMapper specGroupMapper;


    @Autowired
    private SpecParamMapper specParamMapper;

    //根据分类的id，作为查询参数，查询分类对应的规格组
    public List<SpecGroup> querySpecGroups(Long cid) {

        SpecGroup record = new SpecGroup();
        record.setCid(cid);

        List<SpecGroup> specGroups = this.specGroupMapper.select(record);

        specGroups.forEach(specGroup -> {
            SpecParam specParam = new SpecParam();
            specParam.setGroupId(specGroup.getId());
            specGroup.setSpecParams(this.specParamMapper.select(specParam));
        });
        return specGroups;
    }

    //根据规格组的id作为规格参数的查询条件，
    public List<SpecParam> querySpecParam(Long gid,Long cid,Boolean searching,Boolean generic) {
        SpecParam record = new SpecParam();
        record.setGroupId(gid);
        record.setCid(cid);
        record.setSearching(searching);
        record.setGeneric(generic);

        return this.specParamMapper.select(record);
    }
}
